package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.ListNode;

/**
 * @Author fengye
 * @Date 2023/4/10 9:32
 **/
public class MiddleListNode876 {
    public ListNode middleNode(ListNode head) {
        if(head == null || head.next == null) {
            return head;
        }

        ListNode node = head;
        int count = 0;

        while(node != null) {
            node = node.next;
            count++;
        }
        int mid = count/2;
        node = head;
        for(int i=0;i < mid;i++) {
            node = node.next;
        }

        return node;
    }
}
